//
//  BombBossIndicator.m
//  ProjectL
//
//  Created by Nguyen Tan Loc on 3/22/14.
//  Copyright (c) 2014 Nguyen Tan Loc. All rights reserved.
//

#import "BombBossIndicator.h"
#import "MainGameScene.h"

@implementation BombBossIndicator

-(id) initWithPos:(CGPoint)pt
{
    if (self = [super init])
    {
        mTimeExplode = BBOMB_EXPLODE_TIME;
        mCircle1 = [CCSprite spriteWithSpriteFrameName:SFN_CIRCLE_100];
        [mCircle1 setPosition:pt];
        [mCircle1 setScale:1.28f];
        [mCircle1 setColor:CL_RED];
        [[MainGameScene getInstance]._globalBatch addChild:mCircle1 z:Z_ORDER_BOMB];
        
        mCircle2 = [CCSprite spriteWithSpriteFrameName:SFN_CIRCLE_100];
        [mCircle2 setPosition:pt];
        [mCircle2 setScale:0.64f];
        [mCircle2 setColor:CL_RED];
        [[MainGameScene getInstance]._globalBatch addChild:mCircle2 z:Z_ORDER_BOMB];
        
        mCircle3 = [CCSprite spriteWithSpriteFrameName:SFN_CIRCLE_100];
        [mCircle3 setPosition:pt];
        [mCircle3 setScale:0.32f];
        [mCircle3 setColor:CL_RED];
        [[MainGameScene getInstance]._globalBatch addChild:mCircle3 z:Z_ORDER_BOMB];
        
        [self scheduleUpdate];
    }
    return self;
}

-(void) update:(ccTime)delta
{
    mTimeExplode -= delta;
    if (mTimeExplode <= 0)
    {
        mBomb = [[Bomb alloc] init];
        [mBomb setAnchorPoint:ccp(0.5, 0.5)];
        [mBomb setPosition:mCircle3.position];
        [[MainGameScene getInstance]._globalBatch addChild:mBomb z:Z_ORDER_BOMB];
        [mBomb explode];
        [mBomb release];
        [self unscheduleUpdate];
        
        [mCircle1 removeFromParent];
        [mCircle2 removeFromParent];
        [mCircle3 removeFromParent];
        
        mTimeExplode = 0.75;
        [self schedule:@selector(updateToRemove:)];
    }
}

-(void) updateToRemove:(ccTime)delta
{
    mTimeExplode -= delta;
    if (mTimeExplode <= 0)
    {
        [self unschedule:_cmd];
        [self removeFromParent];
//        [mBomb removeFromParent];
    }
}

@end
